package com.top.art.exception;

import com.top.art.constants.CommonErrorCodeEnum;
import com.top.art.vo.ResVO;
import lombok.Data;

/**
 * The type Protocol exception.
 *
 * @author hjh
 */
@Data
public class ArtException extends RuntimeException {

    /**
     * uuid
     */
    private static final long serialVersionUID = -8600304342598915886L;
    private Integer code;

    private String message;


    /**
     * Instantiates a new Protocol exception.
     *
     * @param code the code
     * @param message the message
     */
    public ArtException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    /**
     * Instantiates a new Protocol exception.
     *
     * @param code the code
     * @param message the message
     * @param ex the ex
     */
    public ArtException(int code, String message, Throwable ex) {
        super(message, ex);
        this.code = code;
        this.message = message;
    }

    /**
     * To protocol protocol.
     *
     * @return the protocol
     */
    public ResVO toResult() {
        return new ResVO(code, message);
    }


    /**
     * Build exception art exception.
     *
     * @return the art exception
     */
    public static ArtException buildException() {
        return new ArtException(5000, "系統错误");
    }

    /**
     * Build exception art exception.
     *
     * @param message the message
     * @return the art exception
     */
    public static ArtException buildException(String message) {
        return new ArtException(5100, "message");
    }

    public ArtException(CommonErrorCodeEnum commonErrorCodeEnum) {
        super(commonErrorCodeEnum.getMessage());
        this.code = commonErrorCodeEnum.getCode();
        this.message = commonErrorCodeEnum.getMessage();
    }
}
